package com.fstrat.frontend.webserviceclient;

import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.api.client.config.ClientConfig;
import com.sun.jersey.api.client.config.DefaultClientConfig;
import com.sun.jersey.api.json.JSONConfiguration;

public final class WebResourceFactory {
	
	private final static Client CLIENT = getClientInstance();
	
	private final static String ADDITION_URL = "http://localhost:8080/RAT_SERVICES/rest/addition";
	private final static String USER_URL = "http://127.0.0.1:8080/RAT_SERVICES/rest/user";
	private final static String ANGEBOT_URL = "http://127.0.0.1:8080/RAT_SERVICES/rest/angebot";
	private final static String ANFRAGE_URL = "http://127.0.0.1:8080/RAT_SERVICES/rest/anfrage";
	
	private static final Client getClientInstance(){
		if (CLIENT == null){
			ClientConfig clientConfig = new DefaultClientConfig();
			clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
			return Client.create(clientConfig);
		}else{
			return CLIENT;
		}
	}
	
	public final static WebResource getAdditionInstance(){
		CLIENT.setFollowRedirects(true);
		return CLIENT.resource(ADDITION_URL);
	}
	public final static WebResource getUserInstance(){
		CLIENT.setFollowRedirects(true);
		return CLIENT.resource(USER_URL);
	}
	public final static WebResource getAngebotInstance(){
		CLIENT.setFollowRedirects(true);
		return CLIENT.resource(ANGEBOT_URL);
	}
	public final static WebResource getAnfrageInstance(){
		CLIENT.setFollowRedirects(true);
		return CLIENT.resource(ANFRAGE_URL);
	}
}
